home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
2.2
/
compact-structure.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
6KB
|
210 lines
" NAME compact-structure
AUTHOR neild@cs.man.ac.uk
CONTRIBUTOR neild@cs.man.ac.uk
FUNCTION compact(er) structure copying
ST-VERSIONS 2.2
PREREQUISITES structure-copying
CONFLICTS
DISTRIBUTION global
VERSION 1.1
DATE 27 Feb 1990
SUMMARY compact-structure
The following classes and changes introduce CompactStructureOutputTable and
CompactStructureInputTable. These classes can be used just like their super
classes (those without the prefix Compact) but result in structure files
that can be significantly smaller, 10 - 40% perhaps. Non compact structure
files can be read by CompactStructureInputTable but compact files cannot be
read by StructureInputTable.
"!
StructureInputTable variableSubclass: #CompactStructureInputTable
instanceVariableNames: 'classTable '
classVariableNames: ''
poolDictionaries: ''
category: 'System-Support'!
!CompactStructureInputTable methodsFor: 'structure reading'!
readClass
| class |
stream next.
^stream peek isDigit
ifTrue: [
class _ classTable at: (Integer readFrom: stream radix: 10).
stream next ~= $( ifTrue: [ self syntaxError ].
class ]
ifFalse: [
stream skip: -1.
class _ super readClass.
classTable at: classTable size + 1 put: class.
class ]! !
!CompactStructureInputTable methodsFor: 'initialize-release'!
initialize
super initialize.
classTable _ IdentityDictionary new.! !
!CompactStructureInputTable methodsFor: 'adding'!
grow
"Must copy instance variables when growing"
| theClassTable |
theClassTable _ classTable.
super grow. "does the grow & become"
classTable _ theClassTable! !
!CompactStructureInputTable methodsFor: 'private'!
rehash
"Must copy instance variables when rehashing"
| theClassTable |
theClassTable _ classTable.
super rehash. "does the rehash & become"
classTable _ theClassTable! !
StructureOutputTable variableSubclass: #CompactStructureOutputTable
instanceVariableNames: 'classTable '
classVariableNames: ''
poolDictionaries: ''
category: 'System-Support'!
!CompactStructureOutputTable methodsFor: 'initialize-release'!
initialize
super initialize.
classTable _ IdentityDictionary new.! !
!CompactStructureOutputTable methodsFor: 'id generation'!
putClassIdFor: anObject on: aStream
"If the class of anObject has not been seen before then print its name
onto
aStream and allocate it an integer unique within the classTable. If
its class is
already in the classTable then print the associated integer onto aStream."
(classTable at: anObject class ifAbsent: [
anObject class name printOn: aStream.
classTable at: anObject class put: classTable size + 1.
^self ]) printOn: aStream base: 10! !
!CompactStructureOutputTable methodsFor: 'adding'!
grow
"Must copy instance variables when growing"
| theClassTable |
theClassTable _ classTable.
super grow. "does the grow & become"
classTable _ theClassTable! !
!CompactStructureOutputTable methodsFor: 'private'!
rehash
"Must copy instance variables when rehashing"
| theClassTable |
theClassTable _ classTable.
super rehash. "does the rehash & become"
classTable _ theClassTable! !
!Object methodsFor: 'public structure copying'!
storeCompactStructure
"Writes a (more compact) description of the receiver into a file, in
a way that allows
the object's structure to be reconstructed from the file's contents.
Returns the file's name"
| fileName file |
fileName _ (FileDirectory named: '')
requestFileName: 'Structure file name?'
default: (self class name, '.', self asOop printString, '.structure')
version: #any
ifFail: [].
^fileName ~~ nil
ifTrue:
[
file _ FileStream fileNamed: (fileName ).
Cursor write showWhile: [self storeCompactStructureOn: file].
file close.
fileName]!
storeCompactStructureOn: aStream
"Writes a (more compact) description of the receiver onto aStream,
in a way that allows
the object's structure to be reconstructed from the stream's contents"
CompactStructureOutputTable storeStructureOf: self on: aStream! !
!Object methodsFor: 'structure copying'!
storeStructureOn: aStream structureTable: structureTable
"Stores the definition of an object onto aStream, given that the objects
in structureTable have already been seen. This method is rarely overridden.
The object's id number is written out followed by a letter identifying
its form
of definition and its class name, followed by a pair of parentheses
enclosing
its definition.
This scheme is closely based upon Steve Vegdahl's work presented in
Moving Structures between Smalltalk Images, OOPSLA '86"
structureTable
putIdOf: self
on: aStream
ifNew: [
self isUniqueValue
ifTrue: [aStream nextPut: $U; nextPutAll: self class name.
^self].
structureTable if: self isGlobal: [:expr|
aStream nextPutAll: 'G<'; nextPutAll: expr; nextPut: $>.
^self].
aStream nextPut: $C.
structureTable putClassIdFor: self on: aStream.
aStream nextPut: $(.
self storeDefinitionOn: aStream structureTable: structureTable.
aStream nextPut: $)]! !
!StructureOutputTable methodsFor: 'id generation'!
putClassIdFor: anObject on: aStream
"Print the name of aClass onto aStream."
anObject class name printOn: aStream.! !
!StructureInputTable methodsFor: 'structure reading'!
readClass
stream next.
^Smalltalk at: (stream upTo: $() asSymbol! !
!StructureInputTable methodsFor: 'As yet unclassified'!
readClassAndDefinition
| obj class varCount |
Cursor execute showWhile: [
class _ self readClass.
obj _ (stream peek = $-
ifTrue: [stream skip: 1. class basicNew]
ifFalse: [varCount _ Integer readFrom: stream radix: 10.
varCount == 0 ifTrue: [class basicNew]
ifFalse: [class basicNew: varCount]]).
stream skip: 1.
self at: currentId put: obj].
obj readStructureFrom: stream structureTable: self.
^obj! !